Ext.define('app.customer.agent.rate.grid', {
	extend : "Ext.grid.Panel",
	alias : 'widget.agentRateGridWidget',
	frame : false,
	border : false,
	requires : [ 'app.customer.model.agentReportRate',
			'app.customer.agent.rate.form' ],
	initComponent : function() {
		var me = this;
		var me = this;
		var columns = me.createColumns();
		var store = me.createStore();
		var dockitems = new Array();
		var queryarry = me.createQuery(store);
		if (queryarry != null) {
			me.qf = widget.search(queryarry);
			dockitems.push(me.qf);
		}
		var toolarray = me.createTool();
		if (toolarray.length > 0) {
			dockitems.push(widget.toolbar(toolarray));
		}
		dockitems.push(widget.paging(store));
		Ext.apply(me, {
			store : store,
			columns : columns,
			singleExpand : me.singleExpand || true,
			dockedItems : dockitems
		});
		store.load();
		me.callParent(arguments);
	},
	createTool : function() {
		var me = this;
		var array = new Array();
		utils.pushbtnarray(array, {
			text : '新增',
			handler : function() {
				Ext.create('app.customer.agent.rate.form', {
					parentTarget : me
				}).show();
			}
		});
		utils.pushbtnarray(array, {
			text : '删除',
			handler : function() {
				var rec = utils.single(me);
				if (rec != null) {
					var param = {
						agentReportRateId : rec.get('agentReportRateId')
					};
					evt.confirm(me, '是否删除?', systemUrl
							+ '/boyon/agent/report/rate/delete', param,
							function() {
								me.store.reload();
							});
				} else {
					Ext.Msg.alert('提示', '请选择记录');
				}
			}
		});
		return array;
	},
	createQuery : function(store) {
		var me = this;
		var param = {};
		var array = new Array();
		array.push(widget.queryConfig({
			xtype : 'textfield',
			name : 'customerName',
			fieldLabel : '客户名称:'
		}));
		array.push(widget.queryConfig({
			xtype : 'valueWidget',
			name : 'reportType',
			fieldLabel : '报告类型:',
			valueField : 'value',
			editable : false,
			displayField : 'displayName',
			valueType : 17
		}));
		array.push(widget.queryConfig({
			xtype : 'valueWidget',
			name : 'rateType',
			fieldLabel : '结算类型:',
			valueField : 'value',
			editable : false,
			displayField : 'displayName',
			valueType : 16
		}));
		param['bl'] = 'center';
		param['items'] = array;
		param['ds'] = store;
		var array = new Array();
		param['btn'] = array;
		return param;
	},
	createStore : function() {
		var me = this;
		return widget.ds({
			clazz : 'app.customer.model.agentReportRate',
			url : systemUrl + '/boyon/agent/report/rate/query'
		});
	},
	createColumns : function() {
		var array = new Array();
		array.push(widget.column({
			dataIndex : 'agentReportRateId',
			width : 80,
			text : '结算ID'
		}));
		array.push(widget.column({
			dataIndex : 'customerName',
			width : 240,
			text : '代理商'
		}));
		array.push(widget.column({
			dataIndex : 'reportType',
			text : '报告类型',
			width : 80,
			renderer : function(v) {
				return utils.getValueField('t' + 17, v);
			}
		}));
		array.push(widget.column({
			dataIndex : 'rateType',
			text : '结算类型',
			width : 80,
			renderer : function(v) {
				return utils.getValueField('t' + 16, v);
			}
		}));
		array.push(widget.column({
			dataIndex : 'freeNum',
			width : 120,
			text : '免费数量'
		}));
		array.push(widget.column({
			dataIndex : 'num',
			width : 120,
			text : '报告数量'
		}));
		array.push(widget.column({
			dataIndex : 'price',
			width : 120,
			text : '金额'
		}));
		array.push(widget.column({
			dataIndex : 'rate',
			width : 120,
			text : '比例'
		}));
		return array;
	},
	reloadStore : function() {
		var me = this;
		me.store.reload();
	},
	getRecordData : function() {
		var me = this;
		var rec = utils.single(me);
		return rec;
	}
});